#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "aic_patrol.h"

void aic_patrol::Init()
{
// insert all states in the map
AddState("idle",(statehandler)&aic_patrol::IdleState);
AddState("increment",(statehandler)&aic_patrol::SeekWptState);
AddState("decrement",(statehandler)&aic_patrol::NextWptState);
zfar = 2.0f;

// reset the state
ChangeState("idle");
}


void aic_patrol::IdleState()
{
//printf("IDLE\n"); Sleep(1000);
//if (rand()%5==0) ChangeState("seekwpt");
	if (GetAsyncKeyState('I')!=0) 
		ChangeState("increment");
	else if (GetAsyncKeyState('O')!=0)
		ChangeState("decrement");
		
}


void aic_patrol::SeekWptState()
{
//printf("SEEK\n"); Sleep(1000);
//if (rand()%5==0) ChangeState("nextwpt");

	zfar += 0.016f;
	if (GetAsyncKeyState('P')!=0) 
		ChangeState("idle");
	else if (GetAsyncKeyState('O')!=0)
		ChangeState("decrement");
}

void aic_patrol::NextWptState()
{
//printf("NEXT\n"); Sleep(1000);
//if (rand()%5==0) ChangeState("idle");

		zfar -= 0.016f;
		if(zfar <= 2 ) zfar = 2;
	if (GetAsyncKeyState('P')!=0) 
		ChangeState("idle");
	else if (GetAsyncKeyState('I')!=0)
		ChangeState("increment");
}

const float aic_patrol::getZfar() const {
	return zfar;
}
